package com.rtos.vo.file.blockTableView;

import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableView;
import javafx.scene.control.cell.PropertyValueFactory;

public class BlockTableView {
    private TableView<BlockByte> tableView;
    private TableColumn tcIndex;
    private TableColumn tcByteContent;
    private TableColumn tcStringContent;

    public BlockTableView(TableView tableView, TableColumn tcIndex, TableColumn tcByteContent, TableColumn tcStringContent) {
        this.tableView = tableView;
        this.tcIndex = tcIndex;
        this.tcByteContent = tcByteContent;
        this.tcStringContent = tcStringContent;
        tcIndex.setCellValueFactory(new PropertyValueFactory("index"));
        tcByteContent.setCellValueFactory(new PropertyValueFactory("byteContent"));
        tcStringContent.setCellValueFactory(new PropertyValueFactory("stringContent"));
    }

    public void setBlockBytes(byte[] bytes) {
        ObservableList<BlockByte> list = FXCollections.observableArrayList();

        for(int i = 0; i < bytes.length; ++i) {
            list.add(new BlockByte(i, bytes[i]));
        }

        this.tableView.setItems(list);
    }
}
